<template>
  <div v-if="is_info">{{content}}</div>
  <div v-else class="form_item-radio" style="line-height: 0;">
    <input type="hidden" :name="name" :value="value">
    <el-radio-group v-model="this_value" @change="update_value" :size="size">
      <el-radio-button v-if="button" v-for="row in options" :value="row.value">{{ row.content }}</el-radio-button>
      <el-radio v-else v-for="row in options" :value="row.value">{{ row.content }}</el-radio>
    </el-radio-group>
  </div>
</template>

<script>
import s94Mjs from "s94-js";
import {decode_config} from "@/js/s94_tool.js";

export default {
  _title_: '单选',
  _can_config_: true,
  _can_form_param_public_: true,
  _can_form_param_: true,
  _can_where_param_: true,
  name: "radio",
  props: ['name', 'value', 'config', 'is_info', 'button', 'size', 'is_list'],
  emits: ['update:value', 'change'],
  data(){
    return {
      need_display: true,
      this_value: s94Mjs.to_string(this.value),
    }
  },
  methods: {
    update_value(v){
      this.need_display = false;
      setTimeout(()=>{this.need_display = true;},5);
      this.$emit('update:value', v);
      this.$emit('change', v);
    },
  },
  watch: {
    value(){
      if (!this.need_display) return;
      this.this_value = s94Mjs.to_string(this.value);
    }
  },
  computed: {
    options(){
      let config = decode_config(this.config);
      return config;
    },
    content(){
      let val = this.this_value, res=this.this_value;
      s94Mjs.eachloop(this.options, 'children', function(row){
        let eq = val == row.value;
        if(eq) res = row.content;
        return !eq;
      })
      return res;
    },
  },
}
</script>

<style scoped>

</style>